﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EnvDTE;
using EnvDTE80;
using EnvDTE90;
using EnvDTE100;
using Microsoft.VisualStudio.CommandBars;

namespace GnProjectAssist
{
    public abstract class GnCommand
    {
        //private System.Guid mID = System.Guid.NewGuid();
        private string mName = null;
        public string Name
        {
            get { return mName; }
        }
        private string mButtonText = null;
        public string ButtonText
        {
            get { return mButtonText; }
        }
        private string mTooltipText = null;
        public string TooltipText
        {
            get { return mTooltipText; }
        }
		private IGnPerformCommand mPerform = null;
		public GnProjectAssist.IGnPerformCommand Perform
		{
			get{ return mPerform; }
		}

		public GnCommand( IGnPerformCommand perform, string commandName, string buttonText, string tooltipText )
        {
			mPerform = perform;
            mName = commandName;
            mButtonText = buttonText;
            mTooltipText = tooltipText;
        }

		protected void AddClickEvent( CommandBarControl control )
		{
			CommandBarEvents menuItemHandler = (EnvDTE.CommandBarEvents)GnAssist.Application.DTE.Events.get_CommandBarEvents( control );
			menuItemHandler.Click += new _dispCommandBarControlEvents_ClickEventHandler( MenuItemClick );
		}

		private void MenuItemClick( object commandBarControl, ref bool handled, ref bool cancelDefault )
		{
			try
			{
				Perform.Perform();
			}
			catch// (ExplorerException e)
			{
				//MessageBox.Show(e.Message, "Explorer add in");
			}
		}
    }
}
